package com.challenger.student.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.challenger.student.entity.Apply;
import com.challenger.student.entity.LoanData;
import com.challenger.student.entity.Points;
import com.challenger.student.entity.Student;
import com.challenger.student.entity.StudentSimple;
import com.challenger.student.entity.StudentUsr;
import com.challenger.student.services.StudentService;
import com.challenger.utils.StringUtils;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 学生处理action
 * 
 * @author 古振猛 404879269@qq.com
 *
 */
public class StudentAction extends ActionSupport {
	private static final long serialVersionUID = -8585655980173283033L;
	private StudentService studentService;
	private int inrid;// INRID 编号 Int

	private int sdtid;// 学生表的pk
	private String username;
	private String password;
	private String idnumber;
	// private Student student;
	HashMap<String, Object> jsonMap = new HashMap<String, Object>();

	/**
	 * 积分项目的分值与权重查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findPoints() throws Exception {
		List<Points> pointsList = this.studentService.findPoints();
		for (Points points : pointsList) {
			jsonMap.put(points.getTerm(), points.getRegular());
		}
		return INPUT;
	}

	/**
	 * 查看纵横校园-银校记录 （一个接口）
	 * 
	 * @return
	 */
	public String bankSchoolRec() throws Exception {
		Student student = this.studentService.findStudentByIdnumber(idnumber);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			jsonMap.put("result", 1);

			jsonMap.put("userimage", student.getUsrimage());
			jsonMap.put("truename", student.getTruename());
			jsonMap.put("university", student.getUniversity());
			jsonMap.put("studentid", student.getStudentid());

			int everapplineloan = student.getEverapplineloan();
			int campcrdinfrq = student.getCampcrdinfrq();
			int campcdrincnt = student.getCampcdrincnt();
			int campcrdoutcnt = student.getCampcrdoutcnt();
			String campcrdoutflow = student.getCampcrdoutflow();

			jsonMap.put("everapplineloan", everapplineloan);
			jsonMap.put("campcrdinfrq", campcrdinfrq);
			jsonMap.put("campcdrincnt", campcdrincnt);
			jsonMap.put("campcrdoutcnt", campcrdoutcnt);
			jsonMap.put("campcrdoutflow", campcrdoutflow);
		}

		return INPUT;

	}

	/**
	 * 纵横校园-信用记录 （一个接口）
	 * 
	 * @return
	 * @throws Exception
	 */
	public String creditRec() throws Exception {
		Student student = this.studentService.findStudentByIdnumber(idnumber);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			jsonMap.put("result", 1);

			jsonMap.put("userimage", student.getUsrimage());
			jsonMap.put("truename", student.getTruename());
			jsonMap.put("university", student.getUniversity());
			jsonMap.put("studentid", student.getStudentid());

			// 我的出勤
			String absenteeism = student.getAbsenteeism();
			List<Map<String, Object>> absenteeismList = StringUtils
					.formatStudentProperty(absenteeism);
			jsonMap.put("absenteeism", absenteeismList);

			// 违纪处分
			String punishmentsrecd = student.getPunishmentsrecd();
			List<Map<String, Object>> punishmentsrecdList = StringUtils
					.formatStudentProperty(punishmentsrecd);
			jsonMap.put("punishmentsrecd", punishmentsrecdList);

			// 图书馆记录
			String liboverduerecd = student.getLiboverdueRecd();
			List<Map<String, Object>> liboverdueRecdList = StringUtils
					.formatStudentProperty(liboverduerecd);
			jsonMap.put("liboverduerecd", liboverdueRecdList);

			// 弃考记录
			String absttstsrecd = student.getAbsttstrecd();
			System.out.println(absttstsrecd);
			List<Map<String, Object>> absttestsrecdList = StringUtils
					.formatStudentProperty(absttstsrecd);
			jsonMap.put("absttstsrecd", absttestsrecdList);

			// 作业情况
			String hmwksubmission = student.getHmwsubmissino();
			List<Map<String, Object>> hmwksubmissionList = StringUtils
					.formatStudentProperty(hmwksubmission);
			jsonMap.put("hmwksubmission", hmwksubmissionList);

			// 学杂费管理
			String roomcharge = student.getRoomcharge();
			List<Map<String, Object>> roomchargeList = StringUtils
					.formatStudentProperty(roomcharge);
			jsonMap.put("roomcharge", roomchargeList);

		}

		return INPUT;
	}

	/**
	 * 纵横校园-校园表现,提交申请
	 * 
	 * @return
	 * @throws Exception
	 */
	public String insertCampusBehaviour() throws Exception {
		Student student = this.studentService.findStudentById(sdtid);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			int coacherid = student.getCoacherid();
			Apply apply = new Apply();
			apply.setStuid(sdtid);
			apply.setCoacherid(coacherid);
			apply.setApplytype(applytype);
			apply.setApplyscore(applyscore);
			apply.setApplydetail(applydetail);
			apply.setImages(images);

			Date currentTime = new Date();
			SimpleDateFormat formatter = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String dateString = formatter.format(currentTime);
			apply.setApplydate(dateString);

			int flag = this.studentService.insertApply(apply);
			if (flag == 1) {
				jsonMap.put("result", 1);
			} else {
				jsonMap.put("result", 0);
			}
		}
		return INPUT;
	}

	/**
	 * 纵横校园-校园表现,查看信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findCampusBehaviour() throws Exception {
		Student student = this.studentService.findStudentByIdnumber(idnumber);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			jsonMap.put("result", 1);

			jsonMap.put("userimage", student.getUsrimage());
			jsonMap.put("truename", student.getTruename());
			jsonMap.put("university", student.getUniversity());
			jsonMap.put("studentid", student.getStudentid());

			// 论文发表记录
			String publications = student.getPublications();
			List<Map<String, Object>> publicationsList = StringUtils
					.formatStudentProperty(publications);
			jsonMap.put("publications", publicationsList);

			// 专利申请记录
			String patent = student.getPatent();
			List<Map<String, Object>> patentList = StringUtils
					.formatStudentProperty(patent);
			jsonMap.put("patent", patentList);

			// 奖学金记录
			String scholarship = student.getScholarship();
			List<Map<String, Object>> scholarshipList = StringUtils
					.formatStudentProperty(scholarship);
			jsonMap.put("scholarship", scholarshipList);

			// 社团记录
			String clubactivity = student.getClubactivity();
			List<Map<String, Object>> clubactivityList = StringUtils
					.formatStudentProperty(clubactivity);
			jsonMap.put("clubactivity", clubactivityList);

			// 我的比赛记录
			String competitionrecd = student.getCompetitionrecd();
			List<Map<String, Object>> competitionrecdList = StringUtils
					.formatStudentProperty(competitionrecd);
			jsonMap.put("competitionrecd", competitionrecdList);

			// 实习记录
			String internshiprecd = student.getInternshiprecd();
			List<Map<String, Object>> internshiprecdList = StringUtils
					.formatStudentProperty(internshiprecd);
			jsonMap.put("internshiprecd", internshiprecdList);

			// 课外实践
			String actexprecd = student.getActexprecd();
			List<Map<String, Object>> actexprecdList = StringUtils
					.formatStudentProperty(actexprecd);
			jsonMap.put("actexprecd", actexprecdList);

			// 项目经历
			String programrecd = student.getProgramrecd();
			List<Map<String, Object>> programrecdList = StringUtils
					.formatStudentProperty(programrecd);
			jsonMap.put("programrecd", programrecdList);

			// 学生领袖
			String studentleaderrecd = student.getStudentleaderrecd();
			List<Map<String, Object>> studentleaderrecdList = StringUtils
					.formatStudentProperty(studentleaderrecd);
			jsonMap.put("studentleaderrecd", studentleaderrecdList);

			// 荣誉称号
			String studthonorrecd = student.getStudthonorrecd();
			List<Map<String, Object>> studthonorrecdList = StringUtils
					.formatStudentProperty(studthonorrecd);
			jsonMap.put("studthonorrecd", studthonorrecdList);

			// 相关课程
			String correlatedcurriculum = student.getCorrelatedcurriculum();
			List<Map<String, Object>> correlatedcurriculumList = StringUtils
					.formatStudentProperty(correlatedcurriculum);
			jsonMap.put("correlatedcurriculum", correlatedcurriculumList);

			// 校外大型考试
			String extraschoolexamrecd = student.getExtraschoolexamrecd();
			List<Map<String, Object>> extraschoolexamrecdList = StringUtils
					.formatStudentProperty(extraschoolexamrecd);
			jsonMap.put("extraschoolexamrecd", extraschoolexamrecdList);

			// 挂科记录
			String fallexam = student.getFallexam();
			List<Map<String, Object>> fallexamList = StringUtils
					.formatStudentProperty(fallexam);
			jsonMap.put("fallexam", fallexamList);

			String absenteeism = student.getAbsenteeism();
			List<Map<String, Object>> absenteeismList = StringUtils
					.formatStudentProperty(absenteeism);
			jsonMap.put("absenteeism", absenteeismList);
			// 投资经历
			String investrecd = student.getInvestrecd();
			List<Map<String, Object>> investrecdList = StringUtils
					.formatStudentProperty(investrecd);
			jsonMap.put("investrecd", investrecdList);

		}

		return INPUT;
	}

	/**
	 * 修改密码
	 * 
	 * @return
	 * @throws Exception
	 */
	public String updatePassword() throws Exception {
		StudentUsr studentUsr = new StudentUsr();
		studentUsr.setIdnumber(idnumber);
		studentUsr.setUpword(password);
		int flag = this.studentService.updatePassword(studentUsr);
		if (flag == 1) {
			jsonMap.put("result", 1);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * 新增申请贷款记录
	 * 
	 * @return
	 * @throws Exception
	 */
	public String insertLoanData() throws Exception {
		LoanData loanData = new LoanData();
		loanData.setAmount(amount);
		loanData.setReason(reason);
		loanData.setStuid(sdtid);
		loanData.setPicture(picture);
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(currentTime);
		loanData.setApplydate(dateString);
		int flag = this.studentService.insertLoanData(loanData);
		if (flag == 1) {
			jsonMap.put("result", 1);
		} else {
			jsonMap.put("result", 0);
		}

		return INPUT;
	}

	/**
	 * 显示申请贷款记录
	 * 
	 * @return
	 * @throws Exception
	 */
	public String myloan() throws Exception {
		List<LoanData> loanDatas = this.studentService
				.findLoanDatasByStuId(sdtid);
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (LoanData loanData : loanDatas) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("amount", loanData.getAmount());
			map.put("date", loanData.getApplydate());
			map.put("reason", loanData.getReason());
			map.put("picture", loanData.getPicture());
			map.put("remark", loanData.getRemark());
			result.add(map);
		}

		jsonMap.put("result", result);

		return INPUT;
	}

	/**
	 * 点击““新增经历”申请反馈”查看向教师端提交申请的申请记录以及审核反馈
	 * 
	 * @return
	 * @throws Exception
	 */
	public String applyhistoryrecd() throws Exception {
		List<Apply> applies = this.studentService.findAppliesByStuId(sdtid);

		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();

		for (Apply apply : applies) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("applydetail", apply.getApplydetail());
			map.put("state", apply.getState());
			map.put("remark", apply.getRemark());
			result.add(map);
		}
		jsonMap.put("result", result);
		return INPUT;
	}

	/**
	 * 主页，点击“我的资料” 评估结果（目前）： totalscore 总分, creditscore 诚信, abilityscore 能力
	 * 
	 * @return
	 * @throws Exception
	 * 
	 */
	public String mainPageMyInfo() throws Exception {
		Student student = this.studentService.findStudentByIdnumber(idnumber);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			jsonMap.put("result", 1);
			jsonMap.put("truename", student.getTruename());
			jsonMap.put("nickname", student.getNickname());
			jsonMap.put("gender", student.getGender());
			jsonMap.put("birthday", student.getBirthday());
			jsonMap.put("hometown", student.getHometown());
			jsonMap.put("location", student.getLocation());
			jsonMap.put("idnumber", student.getIdnumber());
			jsonMap.put("userimage", student.getUsrimage());
			jsonMap.put("email", student.getEmail());
			jsonMap.put("phonenumber", student.getPhonenumber());
			jsonMap.put("everappliedloan", student.getEverapplineloan());
			jsonMap.put("university", student.getUniversity());
			jsonMap.put("school", student.getSchool());
			jsonMap.put("class", student.getClasses());
			jsonMap.put("coacher", student.getCoacher());
			jsonMap.put("studentid", student.getStudentid());
			jsonMap.put("edustartdate", student.getEdustartdate());

			List<Points> pointsList = this.studentService.findPoints();

			// 这块要算分数，然后返回
			// 论文发表记录-----------能力
			String publications = student.getPublications();
			double publicationsScore = StringUtils.getScore(publications);
			for (Points points : pointsList) {
				if ("publications".equalsIgnoreCase(points.getTerm())) {
					publicationsScore = publicationsScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}

			// 专利申请记录-----------能力
			String patent = student.getPatent();
			double patentScore = StringUtils.getScore(patent);
			for (Points points : pointsList) {
				if ("patent".equalsIgnoreCase(points.getTerm())) {
					patentScore = patentScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			// 奖学金记录-----------能力
			String scholarship = student.getScholarship();
			double scholarshipScore = StringUtils.getScore(scholarship);
			for (Points points : pointsList) {
				if ("scholarship".equalsIgnoreCase(points.getTerm())) {
					scholarshipScore = scholarshipScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}

			// 社团记录-----------能力
			String clubactivity = student.getClubactivity();
			double clubactivityScore = StringUtils.getScore(clubactivity);
			for (Points points : pointsList) {
				if ("clubactivity".equalsIgnoreCase(points.getTerm())) {
					clubactivityScore = clubactivityScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			// 我的比赛记录-----------能力
			String competitionrecd = student.getCompetitionrecd();

			double competitionrecdScore = StringUtils.getScore(competitionrecd);
			for (Points points : pointsList) {
				if ("competitionrecd".equalsIgnoreCase(points.getTerm())) {
					competitionrecdScore = competitionrecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 实习记录-----------能力
			String internshiprecd = student.getInternshiprecd();
			double internshiprecdScore = StringUtils.getScore(internshiprecd);
			for (Points points : pointsList) {
				if ("internshiprecd".equalsIgnoreCase(points.getTerm())) {
					internshiprecdScore = internshiprecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 课外实践-----------能力
			String actexprecd = student.getActexprecd();
			double actexprecdScore = StringUtils.getScore(actexprecd);
			for (Points points : pointsList) {
				if ("actexprecd".equalsIgnoreCase(points.getTerm())) {
					actexprecdScore = actexprecdScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}

			// 项目经历-----------能力
			String programrecd = student.getProgramrecd();
			double programrecdScore = StringUtils.getScore(programrecd);
			for (Points points : pointsList) {
				if ("programrecd".equalsIgnoreCase(points.getTerm())) {
					programrecdScore = programrecdScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}

			// 学生领袖-----------能力
			String studentleaderrecd = student.getStudentleaderrecd();
			double studentleaderrecdScore = StringUtils
					.getScore(studentleaderrecd);
			for (Points points : pointsList) {
				if ("studentleaderrecd".equalsIgnoreCase(points.getTerm())) {
					studentleaderrecdScore = studentleaderrecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 荣誉称号-----------能力
			String studthonorrecd = student.getStudthonorrecd();
			double studthonorrecdScore = StringUtils.getScore(studthonorrecd);
			for (Points points : pointsList) {
				if ("studentleaderrecd".equalsIgnoreCase(points.getTerm())) {
					studthonorrecdScore = studthonorrecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 相关课程-----------能力
			String correlatedcurriculum = student.getCorrelatedcurriculum();
			double correlatedcurriculumScore = StringUtils
					.getScore(correlatedcurriculum);
			for (Points points : pointsList) {
				if ("studentleaderrecd".equalsIgnoreCase(points.getTerm())) {
					correlatedcurriculumScore = correlatedcurriculumScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 校外大型考试-----------能力
			String extraschoolexamrecd = student.getExtraschoolexamrecd();
			double extraschoolexamrecdScore = StringUtils
					.getScore(extraschoolexamrecd);
			for (Points points : pointsList) {
				if ("extraschoolexamrecd".equalsIgnoreCase(points.getTerm())) {
					extraschoolexamrecdScore = extraschoolexamrecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 挂科记录-----------能力
			String fallexam = student.getFallexam();
			double fallexamScore = StringUtils.getScore(fallexam);
			for (Points points : pointsList) {
				if ("fallexam".equalsIgnoreCase(points.getTerm())) {
					fallexamScore = fallexamScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			// 投资经历-----------能力
			String investrecd = student.getInvestrecd();
			double investrecdScore = StringUtils.getScore(investrecd);
			for (Points points : pointsList) {
				if ("investrecd".equalsIgnoreCase(points.getTerm())) {
					investrecdScore = investrecdScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			// --------------------诚信-----------------------------------------------------
			// 我的出勤---------诚信
			String absenteeism = student.getAbsenteeism();
			double absenteeismScore = StringUtils.getScore(absenteeism);
			for (Points points : pointsList) {
				if ("absenteeism".equalsIgnoreCase(points.getTerm())) {
					absenteeismScore = absenteeismScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}

			// 违纪处分---------诚信
			String punishmentsrecd = student.getPunishmentsrecd();
			double punishmentsrecdScore = StringUtils.getScore(punishmentsrecd);
			for (Points points : pointsList) {
				if ("punishmentsrecd".equalsIgnoreCase(points.getTerm())) {
					punishmentsrecdScore = punishmentsrecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 图书馆记录 ---------诚信
			String liboverduerecd = student.getLiboverdueRecd();
			double liboverduerecdScore = StringUtils.getScore(liboverduerecd);
			for (Points points : pointsList) {
				if ("liboverduerecd".equalsIgnoreCase(points.getTerm())) {
					liboverduerecdScore = liboverduerecdScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			// 弃考记录---------诚信
			String absttstsrecd = student.getAbsttstrecd();
			double absttstsrecdScore = StringUtils.getScore(absttstsrecd);
			for (Points points : pointsList) {
				if ("absttstsrecd".equalsIgnoreCase(points.getTerm())) {
					absttstsrecdScore = absttstsrecdScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			// 作业情况---------诚信
			String hmwksubmission = student.getHmwsubmissino();
			double hmwksubmissionScore = StringUtils.getScore(hmwksubmission);
			for (Points points : pointsList) {
				if ("hmwksubmission".equalsIgnoreCase(points.getTerm())) {
					hmwksubmissionScore = hmwksubmissionScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}
			// 学杂费管理---------诚信
			String roomcharge = student.getRoomcharge();
			double roomchargeScore = StringUtils.getScore(roomcharge);
			for (Points points : pointsList) {
				if ("roomcharge".equalsIgnoreCase(points.getTerm())) {
					roomchargeScore = roomchargeScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}

			double totalscore = 0;
			double creditscore = 0;
			double abilityscore = 0;
			double familyscore = 0;
			// 能力汇总
			abilityscore = publicationsScore + patentScore + scholarshipScore
					+ clubactivityScore + competitionrecdScore
					+ internshiprecdScore + actexprecdScore + programrecdScore
					+ studentleaderrecdScore + studthonorrecdScore
					+ correlatedcurriculumScore + extraschoolexamrecdScore
					+ fallexamScore + investrecdScore;

			// 诚信汇总
			creditscore = punishmentsrecdScore + liboverduerecdScore
					+ absttstsrecdScore + absenteeismScore
					+ hmwksubmissionScore + roomchargeScore;

			// 势力
			int everapplineloan = student.getEverapplineloan();
			double everapplineloanScore = everapplineloan;
			for (Points points : pointsList) {
				if ("everapplineloan".equalsIgnoreCase(points.getTerm())) {
					everapplineloanScore = everapplineloanScore
							* points.getWeight() * points.getEqualscore();
					break;
				}
			}

			int family = student.getFamilyscore();
			double familyscoreScore = family;
			for (Points points : pointsList) {
				if ("familyscore".equalsIgnoreCase(points.getTerm())) {
					familyscoreScore = familyscoreScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			int campcrdscore = student.getCampcrdscore();
			double campcrdscoreScore = campcrdscore;
			for (Points points : pointsList) {
				if ("campcrdscore".equalsIgnoreCase(points.getTerm())) {
					campcrdscoreScore = campcrdscoreScore * points.getWeight()
							* points.getEqualscore();
					break;
				}
			}
			familyscore = everapplineloanScore + campcrdscoreScore
					+ familyscoreScore;

			double totalhonor = creditscore;
			double totalability = abilityscore;
			double totalfamily = familyscore;
			for (Points points : pointsList) {
				if ("totalhonor".equalsIgnoreCase(points.getTerm())) {
					totalhonor = totalhonor * points.getWeight()
							* points.getEqualscore();
					continue;
				}
				if ("totalability".equalsIgnoreCase(points.getTerm())) {
					totalability = totalability * points.getWeight()
							* points.getEqualscore();
					continue;
				}
				if ("totalfamily".equalsIgnoreCase(points.getTerm())) {
					totalfamily = totalfamily * points.getWeight()
							* points.getEqualscore();
					continue;
				}
			}

			totalscore = totalhonor + totalability + totalfamily;
			jsonMap.put("creditscore", creditscore);
			jsonMap.put("abilityscore", abilityscore);
			jsonMap.put("familyscore", familyscore);
			jsonMap.put("totalscore", totalscore);
		}
		return INPUT;
	}

	/**
	 * 主页的顶部
	 * 
	 * @return
	 * @throws Exception
	 */
	public String mainPageTop() throws Exception {
		Student student = this.studentService.findStudentByIdnumber(idnumber);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			jsonMap.put("result", 1);
			jsonMap.put("userimage", student.getUsrimage());
			jsonMap.put("nickname", student.getNickname());
			jsonMap.put("school", student.getSchool());
			jsonMap.put("studentid", student.getStudentid());
		}
		return INPUT;
	}

	/**
	 * 根据教师id，查找学生,简单信息
	 */
	public String findSimpleStudentsByCoacherid() throws Exception {

		List<Student> students = this.studentService
				.findStudentsByCoacherid(inrid);
		if (students != null && students.size() > 0) {
			jsonMap.put("result", 1);

			List<StudentSimple> studentSimples = new ArrayList<StudentSimple>();
			for (Student student : students) {
				studentSimples.add(new StudentSimple(student));
			}
			jsonMap.put("students", studentSimples);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * 根据教师id，查找学生,全部信息
	 */
	public String findStudentsByCoacherid() throws Exception {

		List<Student> students = this.studentService
				.findStudentsByCoacherid(inrid);
		if (students != null && students.size() > 0) {
			jsonMap.put("result", 1);
			jsonMap.put("students", students);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * android端学生登录
	 * 
	 * @return
	 */
	public String login() {
		Map<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("username", username);
		paraMap.put("password", password);

		List<StudentUsr> studentUsrs = this.studentService.login(paraMap);
		if (studentUsrs.size() == 1) {
			jsonMap.put("result", 1);
			String idnumber = studentUsrs.get(0).getIdnumber();
			Student student = this.studentService
					.findStudentByIdnumber(idnumber);
			jsonMap.put("idnumber", idnumber);
			jsonMap.put("sdtid", student.getSdtid());// pk

		} else {
			jsonMap.put("result", 0);
		}
		return Action.INPUT;
	}

	/**
	 * android端学生注册
	 * 
	 * @return
	 * @throws Exception
	 */
	public String register() throws Exception {
		List<StudentUsr> studentUsrs = this.studentService
				.findStudentsByUsername(username);
		if (studentUsrs.size() > 0) {// 用户名已经存在
			jsonMap.put("result", 2);
			return INPUT;
		}
		studentUsrs = studentService.findStudentsByIdnumber(idnumber);
		if (studentUsrs.size() > 0) {// 身份号重了返回3
			jsonMap.put("result", 3);
			return INPUT;
		}
		StudentUsr studentUsr = new StudentUsr();
		studentUsr.setUid(username);
		studentUsr.setUpword(password);
		studentUsr.setIdnumber(idnumber);
		int i = this.studentService.addStudentUsr(studentUsr);
		if (i == 1) {// 成功
			jsonMap.put("result", 1);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * android端更新学生个人信息 
	 * @return
	 * @throws Exception
	 */
	public String updateStudentPersionalInfo() throws Exception {
		Student student = new Student();
		student.setIdnumber(idnumber);
		student.setUsrimage(userimage);
		student.setTruename(truename);
		student.setNickname(nickname);
		student.setGender(gender);
		student.setBirthday(birthday);
		student.setHometown(hometown);
		student.setLocation(location);
		student.setEmail(email);
		student.setPhonenumber(phonenumber);
		student.setEverapplineloan(everapplineloan);
		int i = this.studentService.updateStudentPersionalInfo(student);
		if (i == 1) {// 成功
			jsonMap.put("result", 1);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * android端，完善学生教育信息 
	 * @return
	 * @throws Exception
	 */
	public String updateStudentEduInfo() throws Exception {
		Student student = new Student();
		student.setIdnumber(idnumber);
		student.setUniversity(university);
		student.setSchool(school);
		student.setSpecial(special);
		student.setClasses(classes);
		student.setStudentid(studentid);
		student.setEdustartdate(edustartdate);
		student.setCoacher(coacher);
		System.out.println(student);
		int i = this.studentService.updateStudentEduInfo(student);

		if (i == 1) {// 成功
			jsonMap.put("result", 1);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * android端更新学生家庭信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String updateStudentFamilyInfo() throws Exception {
		Student student = new Student();
		student.setIdnumber(idnumber);
		student.setFname(fname);
		student.setFcompany(fcompany);
		student.setFduty(fduty);
		student.setFphone(fphone);
		student.setMname(mname);
		student.setMcompany(mcompany);
		student.setMduty(mduty);
		student.setMphone(mphone);
		int i = this.studentService.updateStudentFamilyInfo(student);
		if (i == 1) {// 成功
			jsonMap.put("result", 1);
		} else {
			jsonMap.put("result", 0);
		}
		return INPUT;
	}

	/**
	 * 弃用，由于android端说解析不出来，只能弃用了，其实解析挺简单的！？
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findStudentByIdnumber() throws Exception {
		Student student = this.studentService.findStudentByIdnumber(idnumber);
		if (student == null) {
			jsonMap.put("result", 0);
		} else {
			jsonMap.put("result", 1);
			jsonMap.put("student", student);

			String absenteeism = student.getAbsenteeism();
			List<Map<String, Object>> absenteeismList = StringUtils
					.formatStudentProperty(absenteeism);
			jsonMap.put("absenteeism", absenteeismList);

			String actexprecd = student.getActexprecd();
			List<Map<String, Object>> actexprecdList = StringUtils
					.formatStudentProperty(actexprecd);
			jsonMap.put("actexprecd", actexprecdList);

			String clubactivity = student.getClubactivity();
			List<Map<String, Object>> clubactivityList = StringUtils
					.formatStudentProperty(clubactivity);
			jsonMap.put("clubactivity", clubactivityList);

			String competitionrecd = student.getCompetitionrecd();
			List<Map<String, Object>> competitionrecdList = StringUtils
					.formatStudentProperty(competitionrecd);
			jsonMap.put("competitionrecd", competitionrecdList);

			String correlatedcurriculum = student.getCorrelatedcurriculum();
			List<Map<String, Object>> correlatedcurriculumList = StringUtils
					.formatStudentProperty(correlatedcurriculum);
			jsonMap.put("correlatedcurriculum", correlatedcurriculumList);

			String extraschoolexamrecd = student.getExtraschoolexamrecd();
			List<Map<String, Object>> extraschoolexamrecdList = StringUtils
					.formatStudentProperty(extraschoolexamrecd);
			jsonMap.put("extraschoolexamrecd", extraschoolexamrecdList);

			String fallexam = student.getFallexam();
			List<Map<String, Object>> fallexamList = StringUtils
					.formatStudentProperty(fallexam);
			jsonMap.put("fallexam", fallexamList);

			String internshiprecd = student.getInternshiprecd();
			List<Map<String, Object>> internshiprecdList = StringUtils
					.formatStudentProperty(internshiprecd);
			jsonMap.put("internshiprecd", internshiprecdList);

			String liboverdueRecd = student.getLiboverdueRecd();
			List<Map<String, Object>> liboverdueRecdList = StringUtils
					.formatStudentProperty(liboverdueRecd);
			jsonMap.put("liboverdueRecd", liboverdueRecdList);

			String patent = student.getPatent();
			List<Map<String, Object>> patentList = StringUtils
					.formatStudentProperty(patent);
			jsonMap.put("patent", patentList);

			String programrecd = student.getProgramrecd();
			List<Map<String, Object>> programrecdList = StringUtils
					.formatStudentProperty(programrecd);
			jsonMap.put("programrecd", programrecdList);

			String publications = student.getPublications();
			List<Map<String, Object>> publicationsList = StringUtils
					.formatStudentProperty(publications);
			jsonMap.put("publications", publicationsList);

			String punishmentsrecd = student.getPunishmentsrecd();
			List<Map<String, Object>> punishmentsrecdList = StringUtils
					.formatStudentProperty(punishmentsrecd);
			jsonMap.put("punishmentsrecd", punishmentsrecdList);

			String roomcharge = student.getRoomcharge();
			List<Map<String, Object>> roomchargeList = StringUtils
					.formatStudentProperty(roomcharge);
			jsonMap.put("roomcharge", roomchargeList);

			String scholarship = student.getScholarship();
			List<Map<String, Object>> scholarshipList = StringUtils
					.formatStudentProperty(scholarship);
			jsonMap.put("scholarship", scholarshipList);

			String studentleaderrecd = student.getStudentleaderrecd();
			List<Map<String, Object>> studentleaderrecdList = StringUtils
					.formatStudentProperty(studentleaderrecd);
			jsonMap.put("studentleaderrecd", studentleaderrecdList);

			String studthonorrecd = student.getStudthonorrecd();
			List<Map<String, Object>> studthonorrecdList = StringUtils
					.formatStudentProperty(studthonorrecd);
			jsonMap.put("studthonorrecd", studthonorrecdList);

		}

		return INPUT;
	}

	public StudentService getStudentService() {
		return studentService;
	}

	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}

	public HashMap<String, Object> getJsonMap() {
		return jsonMap;
	}

	public void setJsonMap(HashMap<String, Object> jsonMap) {
		this.jsonMap = jsonMap;
	}

	// 学生个人信息
	private String userimage;
	private String truename;
	private String nickname;
	private String gender;
	private String birthday;
	private String hometown;
	private String location;
	private String email;
	private String phonenumber;
	private int everapplineloan;

	public int getInrid() {
		return inrid;
	}

	public void setInrid(int inrid) {
		this.inrid = inrid;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getIdnumber() {
		return idnumber;
	}

	public void setIdnumber(String idnumber) {
		this.idnumber = idnumber;
	}

	public String getUserimage() {
		return userimage;
	}

	public void setUserimage(String userimage) {
		this.userimage = userimage;
	}

	public String getTruename() {
		return truename;
	}

	public void setTruename(String truename) {
		this.truename = truename;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getHometown() {
		return hometown;
	}

	public void setHometown(String hometown) {
		this.hometown = hometown;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhonenumber() {
		return phonenumber;
	}

	public void setPhonenumber(String phonenumber) {
		this.phonenumber = phonenumber;
	}

	public int getEverapplineloan() {
		return everapplineloan;
	}

	public void setEverapplineloan(int everapplineloan) {
		this.everapplineloan = everapplineloan;
	}

	// 学生教育信息
	private String university;
	private String school;
	private String special;
	private int classes;
	private String studentid;
	private String edustartdate;
	private int coacherid;

	private String coacher;

	public String getUniversity() {
		return university;
	}

	public void setUniversity(String university) {
		this.university = university;
	}

	public String getSchool() {
		return school;
	}

	public void setSchool(String school) {
		this.school = school;
	}

	public String getSpecial() {
		return special;
	}

	public void setSpecial(String special) {
		this.special = special;
	}

	public int getClasses() {
		return classes;
	}

	public void setClasses(int classes) {
		this.classes = classes;
	}

	public String getStudentid() {
		return studentid;
	}

	public void setStudentid(String studentid) {
		this.studentid = studentid;
	}

	public String getEdustartdate() {
		return edustartdate;
	}

	public void setEdustartdate(String edustartdate) {
		this.edustartdate = edustartdate;
	}

	public int getCoacherid() {
		return coacherid;
	}

	public void setCoacherid(int coacherid) {
		this.coacherid = coacherid;
	}

	public String getCoacher() {
		return coacher;
	}

	public void setCoacher(String coacher) {
		this.coacher = coacher;
	}

	// 家庭信息
	private String fname;
	private String fcompany;
	private String fduty;
	private String fphone;
	private String mname;
	private String mcompany;
	private String mduty;
	private String mphone;

	public String getFname() {
		return fname;
	}

	public void setFname(String fname) {
		this.fname = fname;
	}

	public String getFcompany() {
		return fcompany;
	}

	public void setFcompany(String fcompany) {
		this.fcompany = fcompany;
	}

	public String getFduty() {
		return fduty;
	}

	public void setFduty(String fduty) {
		this.fduty = fduty;
	}

	public String getFphone() {
		return fphone;
	}

	public void setFphone(String fphone) {
		this.fphone = fphone;
	}

	public String getMname() {
		return mname;
	}

	public void setMname(String mname) {
		this.mname = mname;
	}

	public String getMcompany() {
		return mcompany;
	}

	public void setMcompany(String mcompany) {
		this.mcompany = mcompany;
	}

	public String getMduty() {
		return mduty;
	}

	public void setMduty(String mduty) {
		this.mduty = mduty;
	}

	public String getMphone() {
		return mphone;
	}

	public void setMphone(String mphone) {
		this.mphone = mphone;
	}

	// 教务信息
	private String studentidpw;

	// 学生贷款信息,金额amount;申请理由reason;证明图片Picture;备注remark
	private int amount;
	private String reason;
	private String picture;

	public String getStudentidpw() {
		return studentidpw;
	}

	public void setStudentidpw(String studentidpw) {
		this.studentidpw = studentidpw;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public int getSdtid() {
		return sdtid;
	}

	public void setSdtid(int sdtid) {
		this.sdtid = sdtid;
	}

	// 校园纵横，校园表现，新增申请
	private String applytype;
	private int applyscore;
	private String applydetail;
	private String images;

	public String getApplytype() {
		return applytype;
	}

	public void setApplytype(String applytype) {
		this.applytype = applytype;
	}

	public int getApplyscore() {
		return applyscore;
	}

	public void setApplyscore(int applyscore) {
		this.applyscore = applyscore;
	}

	public String getApplydetail() {
		return applydetail;
	}

	public void setApplydetail(String applydetail) {
		this.applydetail = applydetail;
	}

	public String getImages() {
		return images;
	}

	public void setImages(String images) {
		this.images = images;
	}

}
